package org.taotao.manager.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.taotao.commons.exception.TaotaoBizException;
import org.taotao.commons.util.IDUtils;
import org.taotao.manager.mapper.ItemMapper;
import org.taotao.manager.pojo.Item;
import org.taotao.manager.service.ItemService;

import com.github.pagehelper.Page;
@Service
public class ItemServiceImpl implements ItemService {

	@Autowired
	private ItemMapper itemMapper;
	
	@Override
	public Page<Item> getItemByPage(int page, int rows) {
		try{
			return itemMapper.selectItemByPageNumSize(page, rows);
		}catch (Exception e) {
			throw new TaotaoBizException("查询商品失败",e);
		}
	}
	
	@Transactional
	@Override
	public Long saveItem(Item item) {
		item.setId(IDUtils.genItemId());
		item.setCreated(new Date());
		item.setUpdated(new Date());
		item.setStatus((byte) 1);
		itemMapper.insert(item);
		return item.getId();
	}

	@Override
	public void delete(String ids) {
		String[] iderr = ids.split(",");
		for(String id : iderr){
			itemMapper.deleteByPrimaryKey(Long.parseLong(id));
		}
	}


	

}
